﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using DHQGHN.DAL.Models.DanhMuc;
using DHQGHN.DAL.BO.DanhMuc;
using System.Configuration;
using System.ServiceModel;
using System.Dynamic;
using DHQGHN.DAL.Models.TDT;

namespace DHQGHN.Services.DanhMuc
{
    public class MasterListService : IMasterListService
    {
        log4net.ILog logger = log4net.LogManager.GetLogger(typeof(MasterListService));

        private MasterListBO masterListBO;
        private CommonListBO commonListBO;
        private AdministrativeUnitBO adminUnitBO;
        private HouseHoldBO houseHoldBO;
        private ResidentBO residentBO;
        //private HouseHoldBO houseHoldAfterTDTBO;
        //private ResidentBO residentAfterTDTBO;
        private AddressAdmUnitExtBO addressAdmUnitExtBO;

        #region Constructors
        /// <summary>
        /// 
        /// </summary>
        public MasterListService()
        {
            //string connString = ConfigurationManager.ConnectionStrings["DHQGHN_TDT.ConnectionString"].ConnectionString;
            masterListBO = new MasterListBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            commonListBO = new CommonListBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            adminUnitBO = new AdministrativeUnitBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            houseHoldBO = new HouseHoldBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            residentBO = new ResidentBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            //houseHoldAfterTDTBO = new HouseHoldBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            //residentAfterTDTBO = new ResidentBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
        }
        #endregion

        #region Service Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public IEnumerable<MasterList> GetNewLists(string lastUpdated)
        {
            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                List<MasterList> ret = masterListBO.GetNewLists(_lastUpdated);

                return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public MasterListTablet GetNewListsTablet(string lastUpdated)
        {
            //HeaderInfo h = new HeaderInfo();
            MasterListTablet jret = new MasterListTablet();
            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };


                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    jret.ErrorCode = -2;
                    jret.ErrorMessage = "Tham số PageSize (hoặc PageIdx) sai định dạng!";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;


                    //throw new FaultException<Fault.ValidationFault>(fault);

                }

                List<MasterList> ret = masterListBO.GetNewLists(_lastUpdated);

                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.Data = ret;

                return jret;

                //return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="listName"></param>
        /// <returns></returns>
        public IEnumerable<MasterList> GetAllByListName(string listName)
        {
            try
            {
                if (string.IsNullOrEmpty(listName))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                return masterListBO.GetAll(listName);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listName"></param>
        /// <param name="pageSize"></param>
        /// <param name="pageIdx"></param>
        /// <returns></returns>
        public IEnumerable<MasterList> GetAllByListNamePaging(string listName, string pageSize, string pageIdx)
        {
            try
            {
                if (string.IsNullOrEmpty(listName)
                    || string.IsNullOrEmpty(pageSize)
                    || string.IsNullOrEmpty(pageIdx))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                int ipageSize, ipageIdx;
                if (int.TryParse(pageSize, out ipageSize) == false
                    || int.TryParse(pageIdx, out ipageIdx) == false)
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                return masterListBO.GetAllPaging(listName, ipageSize, ipageIdx);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="listName"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public MasterList GetOneByCode(string listName, string code)
        {
            try
            {
                if (string.IsNullOrEmpty(listName)
                    || string.IsNullOrEmpty(code))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }

                return masterListBO.GetByCode(listName, code);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public CommonListTablet GetNewCommonList(string lastUpdated)
        {
            //HeaderInfo h = new HeaderInfo();
            CommonListTablet jret = new CommonListTablet();
            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };


                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    jret.ErrorCode = -2;
                    jret.ErrorMessage = "Tham số PageSize (hoặc PageIdx) sai định dạng!";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;


                    //throw new FaultException<Fault.ValidationFault>(fault);

                }

                List<CommonList> ret = commonListBO.GetNewLists(_lastUpdated);

                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.Data = ret;

                return jret;

                //return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public CommonListTablet GetNewCommonListPaging(string lastUpdated, string pageSize, string pageIdx)
        {
            //HeaderInfo h = new HeaderInfo();
            CommonListTablet jret = new CommonListTablet();
            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Thiếu tham số",
                        Description = "Thiếu tham số"
                    };


                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.ToString());
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    jret.ErrorCode = -2;
                    jret.ErrorMessage = "Tham số PageSize (hoặc PageIdx) sai định dạng!";
                    jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                    jret.Data = null;

                    return jret;


                    //throw new FaultException<Fault.ValidationFault>(fault);

                }

                int ipageSize, ipageIdx;
                if (int.TryParse(pageSize, out ipageSize) == false
                    || int.TryParse(pageIdx, out ipageIdx) == false)
                {
                    Fault.ValidationFault fault = new Fault.ValidationFault()
                    {
                        Result = false,
                        Message = "Tham số PageSize (hoặc PageIdx) sai định dạng!",
                        Description = "Tham số PageSize (hoặc PageIdx) sai định dạng!"
                    };

                    throw new FaultException<Fault.ValidationFault>(fault);
                }



                List<CommonList> ret = commonListBO.GetNewPaging(_lastUpdated, ipageSize, ipageIdx);

                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.Data = ret;

                return jret;

                //return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public ListDataObject DownloadDanhMuc(string lastUpdated, string pageSize, string pageIdx)
        {
            //HeaderInfo h = new HeaderInfo();
            ListDataObject jret = new ListDataObject();
            jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
            jret.COUNTRY = new List<COUNTRY>();
            jret.DRLS_ISSUER = new List<DRLS_Issuer>();
            jret.ETHNIC = new List<ETHNIC>();
            jret.GENDER = new List<GENDER>();
            jret.HH_RELATIONSHIP = new List<HH_RELATIONSHIP>();
            jret.IDCARD_ISSUER = new List<IDCARD_ISSUER>();
            jret.MARITAL_STATUS = new List<MARITAL_STATUS>();
            jret.PASPORT_ISSUER = new List<PASSPORT_ISSUER>();
            jret.PASSPORT_TYPE = new List<PASSPORT_TYPE>();
            jret.RELIGION = new List<RELIGION>();
            jret.RESIDENT_GROUP = new List<RESIDENT_GROUP>();
            jret.RESIDENT_STATUS = new List<RESIDENT_STATUS>();
            jret.SURVEY_METHOD = new List<SURVEY_METHOD>();
            jret.TAX_CODE_ISSUER = new List<TAX_CODE_ISSUER>();
            jret.ADMINISTRATIVE_UNIT = new List<ADMINISTRATIVE_UNIT>();
            jret.EDUCATION_TRAINING = new List<EDUCATION_TRAINING>();
            jret.OCCUPATION = new List<OCCUPATION>();

            jret.EDUCATION_LEVEL = new List<EDUCATION_LEVEL>();
            jret.TECHNICAL_LEVEL = new List<TECHNICAL_LEVEL>();
            jret.BLOOD_GROUP = new List<BLOOD_GROUP>();
            jret.SERIOUS_DISEASES = new List<SERIOUS_DISEASES>();
            jret.DISABILITY_STATUS = new List<DISABILITY_STATUS>();
            jret.INSURANCE_STATUS = new List<INSURANCE_STATUS>();
            jret.OCCUP_STATUS = new List<OCCUP_STATUS>();
            jret.COURT = new List<COURT>();
            jret.DEATH_CAUSE = new List<DEATH_CAUSE>();
            jret.INSURANCE_TYPE = new List<INSURANCE_TYPE>();


            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch
                {
                    jret.ErrorCode = -2;
                    jret.ErrorMessage = "Tham số lastUpdated sai định dạng!";
                    return jret;
                }

                int ipageSize, ipageIdx;
                if (int.TryParse(pageSize, out ipageSize) == false
                    || int.TryParse(pageIdx, out ipageIdx) == false)
                {

                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageSize (hoặc PageIdx) sai định dạng!";
                    return jret;
                }

                List<COUNTRY> LST_COUNTRY = new List<COUNTRY>();
                List<DRLS_Issuer> LST_DRLS_ISSUER = new List<DRLS_Issuer>();
                List<ETHNIC> LST_ETHNIC = new List<ETHNIC>();
                List<GENDER> LST_GENDER = new List<GENDER>();
                List<HH_RELATIONSHIP> LST_HH_RELATIONSHIP = new List<HH_RELATIONSHIP>();
                List<IDCARD_ISSUER> LST_IDCARD_ISSUER = new List<IDCARD_ISSUER>();
                List<MARITAL_STATUS> LST_MARITAL_STATUS = new List<MARITAL_STATUS>();
                List<PASSPORT_ISSUER> LST_PASPORT_ISSUER = new List<PASSPORT_ISSUER>();
                List<PASSPORT_TYPE> LST_PASSPORT_TYPE = new List<PASSPORT_TYPE>();
                List<RELIGION> LST_RELIGION = new List<RELIGION>();
                List<RESIDENT_GROUP> LST_RESIDENT_GROUP = new List<RESIDENT_GROUP>();
                List<RESIDENT_STATUS> LST_RESIDENT_STATUS = new List<RESIDENT_STATUS>();
                List<SURVEY_METHOD> LST_SURVEY_METHOD = new List<SURVEY_METHOD>();
                List<TAX_CODE_ISSUER> LST_TAX_CODE_ISSUER = new List<TAX_CODE_ISSUER>();
                List<ADMINISTRATIVE_UNIT> LST_ADMINISTRATIVE_UNIT = new List<ADMINISTRATIVE_UNIT>();
                //List<AREA> LST_AREA = new List<AREA>();
                List<AreaBoundPoint> LST_AREA_BOUNDPOINT = new List<AreaBoundPoint>();
                //List<Area_Enum> LST_AREA_ENUM = new List<Area_Enum>();
                List<EDUCATION_TRAINING> LST_EDUCATION_TRAINING = new List<EDUCATION_TRAINING>();
                List<ENUMERATOR> LST_ENUMERATOR = new List<ENUMERATOR>();
                List<HOUSEHOLD> LST_HOUSEHOLD = new List<HOUSEHOLD>();
                List<OCCUPATION> LST_OCCUPATION = new List<OCCUPATION>();
                List<RESIDENT> LST_RESIDENT = new List<RESIDENT>();

                List<EDUCATION_LEVEL> LST_EDUCATION_LEVEL = new List<EDUCATION_LEVEL>();
                List<TECHNICAL_LEVEL> LST_TECHNICAL_LEVEL = new List<TECHNICAL_LEVEL>();
                List<BLOOD_GROUP> LST_BLOOD_GROUP = new List<BLOOD_GROUP>();
                List<SERIOUS_DISEASES> LST_SERIOUS_DISEASES = new List<SERIOUS_DISEASES>();
                List<DISABILITY_STATUS> LST_DISABILITY_STATUS = new List<DISABILITY_STATUS>();
                List<INSURANCE_STATUS> LST_INSURANCE_STATUS = new List<INSURANCE_STATUS>();
                List<OCCUP_STATUS> LST_OCCUP_STATUS = new List<OCCUP_STATUS>();
                List<COURT> LST_COURT = new List<COURT>();
                List<DEATH_CAUSE> LST_DEATH_CAUSE = new List<DEATH_CAUSE>();
                List<INSURANCE_TYPE> LST_INSURANCE_TYPE = new List<INSURANCE_TYPE>();

                #region Gán dữ liệu

                #region CommonList
                //foreach (CommonList item in retOfcommonList)
                //{
                //    if (item.TABLE_NAME == TableName.COUNTRY)
                //    {
                //        #region COUNTRY
                //        Country COUNTRY_OBJ = new Country();
                //        COUNTRY_OBJ.CountryID = item.ID;
                //        COUNTRY_OBJ.CountryCode2 = item.CODE;
                //        COUNTRY_OBJ.CountryName = item.NAME;
                //        COUNTRY_OBJ.Descriptions = item.DESCRIPTIONS;
                //        COUNTRY_OBJ.Deleted = item.DELETED;
                //        COUNTRY_OBJ.StartDate = item.START_DATE;
                //        COUNTRY_OBJ.EndDate = item.END_DATE;
                //        COUNTRY_OBJ.LastUpdated = item.LAST_UPDATED;
                //        LST_COUNTRY.Add(COUNTRY_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.DRLS_ISSUER)
                //    {
                //        #region DRLS_ISSUER
                //        DRLS_Issuer DRLS_ISSUER_OBJ = new DRLS_Issuer();
                //        DRLS_ISSUER_OBJ.DRLS_ISSUER_ID = item.ID;
                //        DRLS_ISSUER_OBJ.CODE = item.CODE;
                //        DRLS_ISSUER_OBJ.NAME = item.NAME;
                //        DRLS_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        DRLS_ISSUER_OBJ.DELETED = item.DELETED;
                //        DRLS_ISSUER_OBJ.START_DATE = item.START_DATE;
                //        DRLS_ISSUER_OBJ.END_DATE = item.END_DATE;
                //        DRLS_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_DRLS_ISSUER.Add(DRLS_ISSUER_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.ETHNIC)
                //    {
                //        #region ETHNIC
                //        ETHNIC ETHNIC_OBJ = new ETHNIC();
                //        ETHNIC_OBJ.ETHNIC_ID = item.ID;
                //        ETHNIC_OBJ.CODE = item.CODE;
                //        ETHNIC_OBJ.NAME = item.NAME;
                //        ETHNIC_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        ETHNIC_OBJ.DELETED = item.DELETED;
                //        ETHNIC_OBJ.START_DATE = item.START_DATE;
                //        ETHNIC_OBJ.END_DATE = item.END_DATE;
                //        ETHNIC_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_ETHNIC.Add(ETHNIC_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.GENDER)
                //    {
                //        #region GENDER
                //        GENDER GENDER_OBJ = new GENDER();
                //        GENDER_OBJ.GENDER_ID = item.ID;
                //        GENDER_OBJ.CODE = item.CODE;
                //        GENDER_OBJ.NAME = item.NAME;
                //        GENDER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        GENDER_OBJ.DELETED = item.DELETED;
                //        GENDER_OBJ.START_DATE = item.START_DATE;
                //        GENDER_OBJ.END_DATE = item.END_DATE;
                //        GENDER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_GENDER.Add(GENDER_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.HH_RELATIONSHIP)
                //    {
                //        #region HH_RELATIONSHIP
                //        HH_RELATIONSHIP HH_RELATIONSHIP_OBJ = new HH_RELATIONSHIP();
                //        HH_RELATIONSHIP_OBJ.HH_RELATIONSHIP_ID = item.ID;
                //        HH_RELATIONSHIP_OBJ.CODE = item.CODE;
                //        HH_RELATIONSHIP_OBJ.NAME = item.NAME;
                //        HH_RELATIONSHIP_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        HH_RELATIONSHIP_OBJ.DELETED = item.DELETED;
                //        HH_RELATIONSHIP_OBJ.START_DATE = item.START_DATE;
                //        HH_RELATIONSHIP_OBJ.END_DATE = item.END_DATE;
                //        HH_RELATIONSHIP_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_HH_RELATIONSHIP.Add(HH_RELATIONSHIP_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.IDCARD_ISSUER)
                //    {
                //        #region IDCARD_ISSUER
                //        IDCARD_ISSUER IDCARD_ISSUER_OBJ = new IDCARD_ISSUER();
                //        IDCARD_ISSUER_OBJ.IDCARD_ISSUER_ID = item.ID;
                //        IDCARD_ISSUER_OBJ.CODE = item.CODE;
                //        IDCARD_ISSUER_OBJ.NAME = item.NAME;
                //        IDCARD_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        IDCARD_ISSUER_OBJ.DELETED = item.DELETED;
                //        IDCARD_ISSUER_OBJ.START_DATE = item.START_DATE;
                //        IDCARD_ISSUER_OBJ.END_DATE = item.END_DATE;
                //        IDCARD_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_IDCARD_ISSUER.Add(IDCARD_ISSUER_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.MARITAL_STATUS)
                //    {
                //        #region MARITAL_STATUS
                //        MARITAL_STATUS MARITAL_STATUS_OBJ = new MARITAL_STATUS();
                //        MARITAL_STATUS_OBJ.MARITAL_STATUS_ID = item.ID;
                //        MARITAL_STATUS_OBJ.CODE = item.CODE;
                //        MARITAL_STATUS_OBJ.NAME = item.NAME;
                //        MARITAL_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        MARITAL_STATUS_OBJ.DELETED = item.DELETED;
                //        MARITAL_STATUS_OBJ.START_DATE = item.START_DATE;
                //        MARITAL_STATUS_OBJ.END_DATE = item.END_DATE;
                //        MARITAL_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_MARITAL_STATUS.Add(MARITAL_STATUS_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.PASPORT_ISSUER)
                //    {
                //        #region PASPORT_ISSUER
                //        PASPORT_ISSUER PASPORT_ISSUER_OBJ = new PASPORT_ISSUER();
                //        PASPORT_ISSUER_OBJ.PASPORT_ISSUER_ID = item.ID;
                //        PASPORT_ISSUER_OBJ.CODE = item.CODE;
                //        PASPORT_ISSUER_OBJ.NAME = item.NAME;
                //        PASPORT_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        PASPORT_ISSUER_OBJ.DELETED = item.DELETED;
                //        PASPORT_ISSUER_OBJ.START_DATE = item.START_DATE;
                //        PASPORT_ISSUER_OBJ.END_DATE = item.END_DATE;
                //        PASPORT_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_PASPORT_ISSUER.Add(PASPORT_ISSUER_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.PASSPORT_TYPE)
                //    {
                //        #region PASSPORT_TYPE
                //        PASSPORT_TYPE PASSPORT_TYPE_OBJ = new PASSPORT_TYPE();
                //        PASSPORT_TYPE_OBJ.PASSPORT_TYPE_ID = item.ID;
                //        PASSPORT_TYPE_OBJ.CODE = item.CODE;
                //        PASSPORT_TYPE_OBJ.NAME = item.NAME;
                //        PASSPORT_TYPE_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        PASSPORT_TYPE_OBJ.DELETED = item.DELETED;
                //        PASSPORT_TYPE_OBJ.START_DATE = item.START_DATE;
                //        PASSPORT_TYPE_OBJ.END_DATE = item.END_DATE;
                //        PASSPORT_TYPE_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_PASSPORT_TYPE.Add(PASSPORT_TYPE_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.RELIGION)
                //    {
                //        #region RELIGION
                //        RELIGION RELIGION_OBJ = new RELIGION();
                //        RELIGION_OBJ.RELIGION_ID = item.ID;
                //        RELIGION_OBJ.CODE = item.CODE;
                //        RELIGION_OBJ.NAME = item.NAME;
                //        RELIGION_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        RELIGION_OBJ.DELETED = item.DELETED;
                //        RELIGION_OBJ.START_DATE = item.START_DATE;
                //        RELIGION_OBJ.END_DATE = item.END_DATE;
                //        RELIGION_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_RELIGION.Add(RELIGION_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.RESIDENT_GROUP)
                //    {
                //        #region RESIDENT_GROUP
                //        RESIDENT_GROUP RESIDENT_GROUP_OBJ = new RESIDENT_GROUP();
                //        RESIDENT_GROUP_OBJ.RESIDENT_GROUP_ID = item.ID;
                //        RESIDENT_GROUP_OBJ.CODE = item.CODE;
                //        RESIDENT_GROUP_OBJ.NAME = item.NAME;
                //        RESIDENT_GROUP_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        RESIDENT_GROUP_OBJ.DELETED = item.DELETED;
                //        RESIDENT_GROUP_OBJ.START_DATE = item.START_DATE;
                //        RESIDENT_GROUP_OBJ.END_DATE = item.END_DATE;
                //        RESIDENT_GROUP_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_RESIDENT_GROUP.Add(RESIDENT_GROUP_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.RESIDENT_STATUS)
                //    {
                //        #region RESIDENT_STATUS
                //        RESIDENT_STATUS RESIDENT_STATUS_OBJ = new RESIDENT_STATUS();
                //        RESIDENT_STATUS_OBJ.RESIDENT_STATUS_ID = item.ID;
                //        RESIDENT_STATUS_OBJ.CODE = item.CODE;
                //        RESIDENT_STATUS_OBJ.NAME = item.NAME;
                //        RESIDENT_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        RESIDENT_STATUS_OBJ.DELETED = item.DELETED;
                //        RESIDENT_STATUS_OBJ.START_DATE = item.START_DATE;
                //        RESIDENT_STATUS_OBJ.END_DATE = item.END_DATE;
                //        RESIDENT_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_RESIDENT_STATUS.Add(RESIDENT_STATUS_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.SURVEY_METHOD)
                //    {
                //        #region SURVEY_METHOD
                //        SURVEY_METHOD SURVEY_METHOD_OBJ = new SURVEY_METHOD();
                //        SURVEY_METHOD_OBJ.SURVEY_METHOD_ID = item.ID;
                //        SURVEY_METHOD_OBJ.CODE = item.CODE;
                //        SURVEY_METHOD_OBJ.NAME = item.NAME;
                //        SURVEY_METHOD_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        SURVEY_METHOD_OBJ.DELETED = item.DELETED;
                //        SURVEY_METHOD_OBJ.START_DATE = item.START_DATE;
                //        SURVEY_METHOD_OBJ.END_DATE = item.END_DATE;
                //        SURVEY_METHOD_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_SURVEY_METHOD.Add(SURVEY_METHOD_OBJ);
                //        #endregion
                //    }
                //    else if (item.TABLE_NAME == TableName.TAX_CODE_ISSUER)
                //    {
                //        #region TAX_CODE_ISSUER
                //        TAX_CODE_ISSUER TAX_CODE_ISSUER_OBJ = new TAX_CODE_ISSUER();
                //        TAX_CODE_ISSUER_OBJ.TAX_CODE_ISSUER_ID = item.ID;
                //        TAX_CODE_ISSUER_OBJ.CODE = item.CODE;
                //        TAX_CODE_ISSUER_OBJ.NAME = item.NAME;
                //        TAX_CODE_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                //        TAX_CODE_ISSUER_OBJ.DELETED = item.DELETED;
                //        TAX_CODE_ISSUER_OBJ.START_DATE = item.START_DATE;
                //        TAX_CODE_ISSUER_OBJ.END_DATE = item.END_DATE;
                //        TAX_CODE_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                //        LST_TAX_CODE_ISSUER.Add(TAX_CODE_ISSUER_OBJ);
                //        #endregion
                //    }
                //}
                #endregion

                List<DownloadList> retOfDownloadList = commonListBO.DownloadListGetNewPaging(_lastUpdated, ipageSize, ipageIdx);

                foreach (DownloadList item in retOfDownloadList)
                {
                    if (item.TABLE_NAME == TableName.COUNTRY)
                    {
                        #region COUNTRY
                        COUNTRY COUNTRY_OBJ = new COUNTRY();
                        COUNTRY_OBJ.COUNTRY_ID = item.ID;
                        COUNTRY_OBJ.COUNTRY_CODE2 = item.CODE;
                        COUNTRY_OBJ.COUNTRY_NAME = item.NAME;
                        COUNTRY_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        COUNTRY_OBJ.DELETED = item.DELETED;
                        COUNTRY_OBJ.START_DATE = item.START_DATE;
                        COUNTRY_OBJ.END_DATE = item.END_DATE;
                        COUNTRY_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_COUNTRY.Add(COUNTRY_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.DRLS_ISSUER)
                    {
                        #region DRLS_ISSUER
                        DRLS_Issuer DRLS_ISSUER_OBJ = new DRLS_Issuer();
                        DRLS_ISSUER_OBJ.DRLS_ISSUER_ID = item.ID;
                        DRLS_ISSUER_OBJ.CODE = item.CODE;
                        DRLS_ISSUER_OBJ.NAME = item.NAME;
                        DRLS_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        DRLS_ISSUER_OBJ.DELETED = item.DELETED;
                        DRLS_ISSUER_OBJ.START_DATE = item.START_DATE;
                        DRLS_ISSUER_OBJ.END_DATE = item.END_DATE;
                        DRLS_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_DRLS_ISSUER.Add(DRLS_ISSUER_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.ETHNIC)
                    {
                        #region ETHNIC
                        ETHNIC ETHNIC_OBJ = new ETHNIC();
                        ETHNIC_OBJ.ETHNIC_ID = item.ID;
                        ETHNIC_OBJ.CODE = item.CODE;
                        ETHNIC_OBJ.NAME = item.NAME;
                        ETHNIC_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        ETHNIC_OBJ.DELETED = item.DELETED;
                        ETHNIC_OBJ.START_DATE = item.START_DATE;
                        ETHNIC_OBJ.END_DATE = item.END_DATE;
                        ETHNIC_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_ETHNIC.Add(ETHNIC_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.GENDER)
                    {
                        #region GENDER
                        GENDER GENDER_OBJ = new GENDER();
                        GENDER_OBJ.GENDER_ID = item.ID;
                        GENDER_OBJ.CODE = item.CODE;
                        GENDER_OBJ.NAME = item.NAME;
                        GENDER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        GENDER_OBJ.DELETED = item.DELETED;
                        GENDER_OBJ.START_DATE = item.START_DATE;
                        GENDER_OBJ.END_DATE = item.END_DATE;
                        GENDER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_GENDER.Add(GENDER_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.HH_RELATIONSHIP)
                    {
                        #region HH_RELATIONSHIP
                        HH_RELATIONSHIP HH_RELATIONSHIP_OBJ = new HH_RELATIONSHIP();
                        HH_RELATIONSHIP_OBJ.HH_RELATIONSHIP_ID = item.ID;
                        HH_RELATIONSHIP_OBJ.CODE = item.CODE;
                        HH_RELATIONSHIP_OBJ.NAME = item.NAME;
                        HH_RELATIONSHIP_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        HH_RELATIONSHIP_OBJ.DELETED = item.DELETED;
                        HH_RELATIONSHIP_OBJ.START_DATE = item.START_DATE;
                        HH_RELATIONSHIP_OBJ.END_DATE = item.END_DATE;
                        HH_RELATIONSHIP_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_HH_RELATIONSHIP.Add(HH_RELATIONSHIP_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.IDCARD_ISSUER)
                    {
                        #region IDCARD_ISSUER
                        IDCARD_ISSUER IDCARD_ISSUER_OBJ = new IDCARD_ISSUER();
                        IDCARD_ISSUER_OBJ.IDCARD_ISSUER_ID = item.ID;
                        IDCARD_ISSUER_OBJ.CODE = item.CODE;
                        IDCARD_ISSUER_OBJ.NAME = item.NAME;
                        IDCARD_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        IDCARD_ISSUER_OBJ.DELETED = item.DELETED;
                        IDCARD_ISSUER_OBJ.START_DATE = item.START_DATE;
                        IDCARD_ISSUER_OBJ.END_DATE = item.END_DATE;
                        IDCARD_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_IDCARD_ISSUER.Add(IDCARD_ISSUER_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.MARITAL_STATUS)
                    {
                        #region MARITAL_STATUS
                        MARITAL_STATUS MARITAL_STATUS_OBJ = new MARITAL_STATUS();
                        MARITAL_STATUS_OBJ.MARITAL_STATUS_ID = item.ID;
                        MARITAL_STATUS_OBJ.CODE = item.CODE;
                        MARITAL_STATUS_OBJ.NAME = item.NAME;
                        MARITAL_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        MARITAL_STATUS_OBJ.DELETED = item.DELETED;
                        MARITAL_STATUS_OBJ.START_DATE = item.START_DATE;
                        MARITAL_STATUS_OBJ.END_DATE = item.END_DATE;
                        MARITAL_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_MARITAL_STATUS.Add(MARITAL_STATUS_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.PASSPORT_ISSUER)
                    {
                        #region PASPORT_ISSUER
                        PASSPORT_ISSUER PASPORT_ISSUER_OBJ = new PASSPORT_ISSUER();
                        PASPORT_ISSUER_OBJ.PASSPORT_ISSUER_ID = item.ID;
                        PASPORT_ISSUER_OBJ.CODE = item.CODE;
                        PASPORT_ISSUER_OBJ.NAME = item.NAME;
                        PASPORT_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        PASPORT_ISSUER_OBJ.DELETED = item.DELETED;
                        PASPORT_ISSUER_OBJ.START_DATE = item.START_DATE;
                        PASPORT_ISSUER_OBJ.END_DATE = item.END_DATE;
                        PASPORT_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_PASPORT_ISSUER.Add(PASPORT_ISSUER_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.PASSPORT_TYPE)
                    {
                        #region PASSPORT_TYPE
                        PASSPORT_TYPE PASSPORT_TYPE_OBJ = new PASSPORT_TYPE();
                        PASSPORT_TYPE_OBJ.PASSPORT_TYPE_ID = item.ID;
                        PASSPORT_TYPE_OBJ.CODE = item.CODE;
                        PASSPORT_TYPE_OBJ.NAME = item.NAME;
                        PASSPORT_TYPE_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        PASSPORT_TYPE_OBJ.DELETED = item.DELETED;
                        PASSPORT_TYPE_OBJ.START_DATE = item.START_DATE;
                        PASSPORT_TYPE_OBJ.END_DATE = item.END_DATE;
                        PASSPORT_TYPE_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_PASSPORT_TYPE.Add(PASSPORT_TYPE_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.RELIGION)
                    {
                        #region RELIGION
                        RELIGION RELIGION_OBJ = new RELIGION();
                        RELIGION_OBJ.RELIGION_ID = item.ID;
                        RELIGION_OBJ.CODE = item.CODE;
                        RELIGION_OBJ.NAME = item.NAME;
                        RELIGION_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        RELIGION_OBJ.DELETED = item.DELETED;
                        RELIGION_OBJ.START_DATE = item.START_DATE;
                        RELIGION_OBJ.END_DATE = item.END_DATE;
                        RELIGION_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_RELIGION.Add(RELIGION_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.RESIDENT_GROUP)
                    {
                        #region RESIDENT_GROUP
                        RESIDENT_GROUP RESIDENT_GROUP_OBJ = new RESIDENT_GROUP();
                        RESIDENT_GROUP_OBJ.RESIDENT_GROUP_ID = item.ID;
                        RESIDENT_GROUP_OBJ.CODE = item.CODE;
                        RESIDENT_GROUP_OBJ.NAME = item.NAME;
                        RESIDENT_GROUP_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        RESIDENT_GROUP_OBJ.DELETED = item.DELETED;
                        RESIDENT_GROUP_OBJ.START_DATE = item.START_DATE;
                        RESIDENT_GROUP_OBJ.END_DATE = item.END_DATE;
                        RESIDENT_GROUP_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_RESIDENT_GROUP.Add(RESIDENT_GROUP_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.RESIDENT_STATUS)
                    {
                        #region RESIDENT_STATUS
                        RESIDENT_STATUS RESIDENT_STATUS_OBJ = new RESIDENT_STATUS();
                        RESIDENT_STATUS_OBJ.RESIDENT_STATUS_ID = item.ID;
                        RESIDENT_STATUS_OBJ.CODE = item.CODE;
                        RESIDENT_STATUS_OBJ.NAME = item.NAME;
                        RESIDENT_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        RESIDENT_STATUS_OBJ.DELETED = item.DELETED;
                        RESIDENT_STATUS_OBJ.START_DATE = item.START_DATE;
                        RESIDENT_STATUS_OBJ.END_DATE = item.END_DATE;
                        RESIDENT_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_RESIDENT_STATUS.Add(RESIDENT_STATUS_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.SURVEY_METHOD)
                    {
                        #region SURVEY_METHOD
                        SURVEY_METHOD SURVEY_METHOD_OBJ = new SURVEY_METHOD();
                        SURVEY_METHOD_OBJ.SURVEY_METHOD_ID = item.ID;
                        SURVEY_METHOD_OBJ.CODE = item.CODE;
                        SURVEY_METHOD_OBJ.NAME = item.NAME;
                        SURVEY_METHOD_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        SURVEY_METHOD_OBJ.DELETED = item.DELETED;
                        SURVEY_METHOD_OBJ.START_DATE = item.START_DATE;
                        SURVEY_METHOD_OBJ.END_DATE = item.END_DATE;
                        SURVEY_METHOD_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_SURVEY_METHOD.Add(SURVEY_METHOD_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.TAX_CODE_ISSUER)
                    {
                        #region TAX_CODE_ISSUER
                        TAX_CODE_ISSUER TAX_CODE_ISSUER_OBJ = new TAX_CODE_ISSUER();
                        TAX_CODE_ISSUER_OBJ.TAX_CODE_ISSUER_ID = item.ID;
                        TAX_CODE_ISSUER_OBJ.CODE = item.CODE;
                        TAX_CODE_ISSUER_OBJ.NAME = item.NAME;
                        TAX_CODE_ISSUER_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        TAX_CODE_ISSUER_OBJ.DELETED = item.DELETED;
                        TAX_CODE_ISSUER_OBJ.START_DATE = item.START_DATE;
                        TAX_CODE_ISSUER_OBJ.END_DATE = item.END_DATE;
                        TAX_CODE_ISSUER_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_TAX_CODE_ISSUER.Add(TAX_CODE_ISSUER_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.ADMINISTRATIVE_UNIT)
                    {
                        #region ADMINISTRATIVE_UNIT
                        ADMINISTRATIVE_UNIT ADMINISTRATIVE_UNIT_OBJ = new ADMINISTRATIVE_UNIT();
                        ADMINISTRATIVE_UNIT_OBJ.ADM_UNIT_ID = item.ID;
                        ADMINISTRATIVE_UNIT_OBJ.CODE = item.CODE;
                        ADMINISTRATIVE_UNIT_OBJ.ADM_NAME = item.NAME;
                        ADMINISTRATIVE_UNIT_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        ADMINISTRATIVE_UNIT_OBJ.DELETED = item.DELETED;
                        ADMINISTRATIVE_UNIT_OBJ.START_DATE = item.START_DATE;
                        ADMINISTRATIVE_UNIT_OBJ.END_DATE = item.END_DATE;
                        ADMINISTRATIVE_UNIT_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        ADMINISTRATIVE_UNIT_OBJ.ADM_TYPE = item.ADMINIS_TYPE;
                        ADMINISTRATIVE_UNIT_OBJ.COMMUNE_CODE = item.COMMUNE_CODE;
                        ADMINISTRATIVE_UNIT_OBJ.COMMUNE_NAME = item.COMMUNE_NAME;
                        ADMINISTRATIVE_UNIT_OBJ.DISTRICT_CODE = item.DISTRICT_CODE;
                        ADMINISTRATIVE_UNIT_OBJ.DISTRICT_NAME = item.DISTRICT_NAME;
                        ADMINISTRATIVE_UNIT_OBJ.LEVELS = item.LEVELS;
                        ADMINISTRATIVE_UNIT_OBJ.P_CODE = item.P_CODE;
                        ADMINISTRATIVE_UNIT_OBJ.P_ID = item.P_ID;
                        ADMINISTRATIVE_UNIT_OBJ.PROVINCE_CODE = item.PROVINCE_CODE;
                        ADMINISTRATIVE_UNIT_OBJ.PROVINCE_NAME = item.PROVINCE_NAME;
                        //ADMINISTRATIVE_UNIT_OBJ.RECODE_COUNT = item.RECODE_COUNT;

                        LST_ADMINISTRATIVE_UNIT.Add(ADMINISTRATIVE_UNIT_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.EDUCATION_TRAINING)
                    {
                        #region EDUCATION_TRAINING
                        EDUCATION_TRAINING EDUCATION_TRAINING_OBJ = new EDUCATION_TRAINING();
                        EDUCATION_TRAINING_OBJ.EDUCATION_TRAINING_ID = item.ID;
                        EDUCATION_TRAINING_OBJ.CODE = item.CODE;
                        EDUCATION_TRAINING_OBJ.NAME = item.NAME;
                        EDUCATION_TRAINING_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        EDUCATION_TRAINING_OBJ.DELETED = item.DELETED;
                        EDUCATION_TRAINING_OBJ.START_DATE = item.START_DATE;
                        EDUCATION_TRAINING_OBJ.END_DATE = item.END_DATE;
                        EDUCATION_TRAINING_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        EDUCATION_TRAINING_OBJ.LEVEL = item.LEVELS;
                        EDUCATION_TRAINING_OBJ.PARENT = item.P_ID;

                        LST_EDUCATION_TRAINING.Add(EDUCATION_TRAINING_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.OCCUPATION)
                    {
                        #region OCCUPATION
                        OCCUPATION OCCUPATION_OBJ = new OCCUPATION();
                        OCCUPATION_OBJ.OCCUPATION_ID = item.ID;
                        OCCUPATION_OBJ.CODE = item.CODE;
                        OCCUPATION_OBJ.NAME = item.NAME;
                        OCCUPATION_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        OCCUPATION_OBJ.DELETED = item.DELETED;
                        OCCUPATION_OBJ.START_DATE = item.START_DATE;
                        OCCUPATION_OBJ.END_DATE = item.END_DATE;
                        OCCUPATION_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        OCCUPATION_OBJ.LEVEL = item.LEVELS;
                        OCCUPATION_OBJ.PARENT = item.P_ID;

                        LST_OCCUPATION.Add(OCCUPATION_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.EDUCATION_LEVEL)
                    {
                        #region EDUCATION_LEVEL
                        EDUCATION_LEVEL EDUCATION_LEVEL_OBJ = new EDUCATION_LEVEL();
                        EDUCATION_LEVEL_OBJ.EDUCATION_LEVEL_ID = item.ID;
                        EDUCATION_LEVEL_OBJ.CODE = item.CODE;
                        EDUCATION_LEVEL_OBJ.NAME = item.NAME;
                        EDUCATION_LEVEL_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        EDUCATION_LEVEL_OBJ.DELETED = item.DELETED;
                        EDUCATION_LEVEL_OBJ.START_DATE = item.START_DATE;
                        EDUCATION_LEVEL_OBJ.END_DATE = item.END_DATE;
                        EDUCATION_LEVEL_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_EDUCATION_LEVEL.Add(EDUCATION_LEVEL_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.TECHNICAL_LEVEL)
                    {
                        #region TECHNICAL_LEVEL
                        TECHNICAL_LEVEL TECHNICAL_LEVEL_OBJ = new TECHNICAL_LEVEL();
                        TECHNICAL_LEVEL_OBJ.TECHNICAL_LEVEL_ID = item.ID;
                        TECHNICAL_LEVEL_OBJ.CODE = item.CODE;
                        TECHNICAL_LEVEL_OBJ.NAME = item.NAME;
                        TECHNICAL_LEVEL_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        TECHNICAL_LEVEL_OBJ.DELETED = item.DELETED;
                        TECHNICAL_LEVEL_OBJ.START_DATE = item.START_DATE;
                        TECHNICAL_LEVEL_OBJ.END_DATE = item.END_DATE;
                        TECHNICAL_LEVEL_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_TECHNICAL_LEVEL.Add(TECHNICAL_LEVEL_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.BLOOD_GROUP)
                    {
                        #region BLOOD_GROUP
                        BLOOD_GROUP BLOOD_GROUP_OBJ = new BLOOD_GROUP();
                        BLOOD_GROUP_OBJ.BLOOD_GROUP_ID = item.ID;
                        BLOOD_GROUP_OBJ.CODE = item.CODE;
                        BLOOD_GROUP_OBJ.NAME = item.NAME;
                        BLOOD_GROUP_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        BLOOD_GROUP_OBJ.DELETED = item.DELETED;
                        BLOOD_GROUP_OBJ.START_DATE = item.START_DATE;
                        BLOOD_GROUP_OBJ.END_DATE = item.END_DATE;
                        BLOOD_GROUP_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_BLOOD_GROUP.Add(BLOOD_GROUP_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.SERIOUS_DISEASES)
                    {
                        #region SERIOUS_DISEASES
                        SERIOUS_DISEASES SERIOUS_DISEASES_OBJ = new SERIOUS_DISEASES();
                        SERIOUS_DISEASES_OBJ.SERIOUS_DISEASES_ID = item.ID;
                        SERIOUS_DISEASES_OBJ.CODE = item.CODE;
                        SERIOUS_DISEASES_OBJ.NAME = item.NAME;
                        SERIOUS_DISEASES_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        SERIOUS_DISEASES_OBJ.DELETED = item.DELETED;
                        SERIOUS_DISEASES_OBJ.START_DATE = item.START_DATE;
                        SERIOUS_DISEASES_OBJ.END_DATE = item.END_DATE;
                        SERIOUS_DISEASES_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_SERIOUS_DISEASES.Add(SERIOUS_DISEASES_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.DISABILITY_STATUS)
                    {
                        #region DISABILITY_STATUS
                        DISABILITY_STATUS DISABILITY_STATUS_OBJ = new DISABILITY_STATUS();
                        DISABILITY_STATUS_OBJ.DISABILITY_STATUS_ID = item.ID;
                        DISABILITY_STATUS_OBJ.CODE = item.CODE;
                        DISABILITY_STATUS_OBJ.NAME = item.NAME;
                        DISABILITY_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        DISABILITY_STATUS_OBJ.DELETED = item.DELETED;
                        DISABILITY_STATUS_OBJ.START_DATE = item.START_DATE;
                        DISABILITY_STATUS_OBJ.END_DATE = item.END_DATE;
                        DISABILITY_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_DISABILITY_STATUS.Add(DISABILITY_STATUS_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.INSURANCE_STATUS)
                    {
                        #region INSURANCE_STATUS
                        INSURANCE_STATUS INSURANCE_STATUS_OBJ = new INSURANCE_STATUS();
                        INSURANCE_STATUS_OBJ.INSURANCE_STATUS_ID = item.ID;
                        INSURANCE_STATUS_OBJ.CODE = item.CODE;
                        INSURANCE_STATUS_OBJ.NAME = item.NAME;
                        INSURANCE_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        INSURANCE_STATUS_OBJ.DELETED = item.DELETED;
                        INSURANCE_STATUS_OBJ.START_DATE = item.START_DATE;
                        INSURANCE_STATUS_OBJ.END_DATE = item.END_DATE;
                        INSURANCE_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_INSURANCE_STATUS.Add(INSURANCE_STATUS_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.OCCUP_STATUS)
                    {
                        #region OCCUP_STATUS
                        OCCUP_STATUS OCCUP_STATUS_OBJ = new OCCUP_STATUS();
                        OCCUP_STATUS_OBJ.OCCUP_STATUS_ID = item.ID;
                        OCCUP_STATUS_OBJ.CODE = item.CODE;
                        OCCUP_STATUS_OBJ.NAME = item.NAME;
                        OCCUP_STATUS_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        OCCUP_STATUS_OBJ.DELETED = item.DELETED;
                        OCCUP_STATUS_OBJ.START_DATE = item.START_DATE;
                        OCCUP_STATUS_OBJ.END_DATE = item.END_DATE;
                        OCCUP_STATUS_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_OCCUP_STATUS.Add(OCCUP_STATUS_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.COURT)
                    {
                        #region COURT
                        COURT COURT_OBJ = new COURT();
                        COURT_OBJ.COURT_ID = item.ID;
                        COURT_OBJ.CODE = item.CODE;
                        COURT_OBJ.NAME = item.NAME;
                        COURT_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        COURT_OBJ.DELETED = item.DELETED;
                        COURT_OBJ.START_DATE = item.START_DATE;
                        COURT_OBJ.END_DATE = item.END_DATE;
                        COURT_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        COURT_OBJ.PARENT_ID = item.P_CODE;
                        COURT_OBJ.LEVELS = item.LEVELS;
                        LST_COURT.Add(COURT_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.DEATH_CAUSE)
                    {
                        #region DEATH_CAUSE
                        DEATH_CAUSE DEATH_CAUSE_OBJ = new DEATH_CAUSE();
                        DEATH_CAUSE_OBJ.DEATH_CAUSE_ID = item.ID;
                        DEATH_CAUSE_OBJ.CODE = item.CODE;
                        DEATH_CAUSE_OBJ.NAME = item.NAME;
                        DEATH_CAUSE_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        DEATH_CAUSE_OBJ.DELETED = item.DELETED;
                        DEATH_CAUSE_OBJ.START_DATE = item.START_DATE;
                        DEATH_CAUSE_OBJ.END_DATE = item.END_DATE;
                        DEATH_CAUSE_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_DEATH_CAUSE.Add(DEATH_CAUSE_OBJ);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.INSURANCE_TYPE)
                    {
                        #region INSURANCE_TYPE
                        INSURANCE_TYPE INSURANCE_TYPE_OBJ = new INSURANCE_TYPE();
                        INSURANCE_TYPE_OBJ.INSURANCE_TYPE_ID = item.ID;
                        INSURANCE_TYPE_OBJ.CODE = item.CODE;
                        INSURANCE_TYPE_OBJ.NAME = item.NAME;
                        INSURANCE_TYPE_OBJ.DESCRIPTIONS = item.DESCRIPTIONS;
                        INSURANCE_TYPE_OBJ.DELETED = item.DELETED;
                        INSURANCE_TYPE_OBJ.START_DATE = item.START_DATE;
                        INSURANCE_TYPE_OBJ.END_DATE = item.END_DATE;
                        INSURANCE_TYPE_OBJ.LAST_UPDATED = item.LAST_UPDATED;
                        LST_INSURANCE_TYPE.Add(INSURANCE_TYPE_OBJ);
                        #endregion
                    }
                }

                #endregion

                jret.COUNTRY = LST_COUNTRY;
                jret.DRLS_ISSUER = LST_DRLS_ISSUER;
                jret.ETHNIC = LST_ETHNIC;
                jret.GENDER = LST_GENDER;
                jret.HH_RELATIONSHIP = LST_HH_RELATIONSHIP;
                jret.IDCARD_ISSUER = LST_IDCARD_ISSUER;
                jret.MARITAL_STATUS = LST_MARITAL_STATUS;
                jret.PASPORT_ISSUER = LST_PASPORT_ISSUER;
                jret.PASSPORT_TYPE = LST_PASSPORT_TYPE;
                jret.RELIGION = LST_RELIGION;
                jret.RESIDENT_GROUP = LST_RESIDENT_GROUP;
                jret.RESIDENT_STATUS = LST_RESIDENT_STATUS;
                jret.SURVEY_METHOD = LST_SURVEY_METHOD;
                jret.TAX_CODE_ISSUER = LST_TAX_CODE_ISSUER;
                jret.ADMINISTRATIVE_UNIT = LST_ADMINISTRATIVE_UNIT;
                jret.EDUCATION_TRAINING = LST_EDUCATION_TRAINING;
                jret.OCCUPATION = LST_OCCUPATION;
                jret.EDUCATION_LEVEL = LST_EDUCATION_LEVEL;
                jret.TECHNICAL_LEVEL = LST_TECHNICAL_LEVEL;
                jret.BLOOD_GROUP = LST_BLOOD_GROUP;
                jret.SERIOUS_DISEASES = LST_SERIOUS_DISEASES;
                jret.DISABILITY_STATUS = LST_DISABILITY_STATUS;
                jret.INSURANCE_STATUS = LST_INSURANCE_STATUS;
                jret.OCCUP_STATUS = LST_OCCUP_STATUS;
                jret.COURT = LST_COURT;
                jret.DEATH_CAUSE = LST_DEATH_CAUSE;
                jret.INSURANCE_TYPE = LST_INSURANCE_TYPE;


                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.RecordCount = retOfDownloadList.Count;
                jret.CurrentTime = System.Convert.ToInt64(DateTime.Now.ToString("yyyyMMddHHmmss", null)); //DHQGHN.Common.Utils.GetCurrentTimeNow();

                return jret;

                //return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        public ADDRESS_ADMUNITEXT_RET DownloadAddressAndAdmUnitExt(string userName, string lastUpdated, string pageSize, string pageIdx)
        {
            addressAdmUnitExtBO = new AddressAdmUnitExtBO(DHQGHN.DAL.Common.ConnectionUtil.TKTHDS_TDT_CONNECTION_STRING);
            //HeaderInfo h = new HeaderInfo();
            ADDRESS_ADMUNITEXT_RET jret = new ADDRESS_ADMUNITEXT_RET();
            jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
            jret.ADDRESS = new List<ADDRESS>();
            jret.ADM_UNIT_EXT = new List<ADM_UNIT_EXT>();


            try
            {
                if (string.IsNullOrEmpty(lastUpdated))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                else if (DHQGHN.Common.Utils.IsNullOrEmptyOverride(userName))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }

                string formatString = "yyyyMMddHHmmss";
                //string sample = "20100611221912";
                DateTime _lastUpdated;
                try
                {
                    _lastUpdated = DateTime.ParseExact(lastUpdated, formatString, null);
                }
                catch
                {
                    jret.ErrorCode = -2;
                    jret.ErrorMessage = "Tham số lastUpdated sai định dạng!";
                    return jret;
                }

                int ipageSize, ipageIdx;
                if (int.TryParse(pageSize, out ipageSize) == false
                    || int.TryParse(pageIdx, out ipageIdx) == false)
                {

                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageSize (hoặc PageIdx) sai định dạng!";
                    return jret;
                }

                List<ADDRESS> addressList = new List<ADDRESS>();
                List<ADM_UNIT_EXT> admUnitExtList = new List<ADM_UNIT_EXT>();



                List<ADDRESS_ADMUNITEXT> retOfDownloadList = addressAdmUnitExtBO.GetAddressAdmUnitExtPaging(userName, _lastUpdated, ipageSize, ipageIdx);

                foreach (ADDRESS_ADMUNITEXT item in retOfDownloadList)
                {
                    if (item.TABLE_NAME == TableName.ADDRESS)
                    {
                        #region ADDRESS
                        ADDRESS address = new ADDRESS();
                        address.ADDRESS_DETAILS = item.ADDRESS_DETAILS;
                        address.ADDRESS_ID = item.ID;
                        address.COUNTRY_ID = item.COUNTRY_ID;
                        address.ADM_UNIT_EXT_ID = item.ADM_UNIT_EXT_ID;
                        address.GPS_ACCURACY = item.GPS_ACCURACY;
                        address.GPS_LONGITUDE = item.GPS_LONGITUDE;
                        address.GPS_LATITUDE = item.GPS_LATITUDE;
                        address.CODE = item.CODE;
                        address.NAME = item.NAME;
                        address.DESCRIPTIONS = item.DESCRIPTIONS;
                        address.DELETED = item.DELETED;
                        address.START_DATE = item.START_DATE;
                        address.END_DATE = item.END_DATE;
                        address.LAST_UPDATED = item.LAST_UPDATED;
                        addressList.Add(address);
                        #endregion
                    }
                    else if (item.TABLE_NAME == TableName.ADM_UNIT_EXT)
                    {
                        #region ADM_UNIT_EXT
                        ADM_UNIT_EXT aDM_UNIT_EXT = new ADM_UNIT_EXT();
                        aDM_UNIT_EXT.ADM_UNIT_EXT_ID = item.ID;
                        aDM_UNIT_EXT.CODE = item.CODE;
                        aDM_UNIT_EXT.NAME = item.NAME;
                        aDM_UNIT_EXT.ADM_UNIT_EXT_TYPE = item.ADM_UNIT_EXT_TYPE;
                        aDM_UNIT_EXT.ADM_UNIT_ID = item.ADM_UNIT_ID;
                        aDM_UNIT_EXT.AREA_ID = item.AREA_ID;
                        aDM_UNIT_EXT.PARENT_ID = item.PARENT_ID;
                        aDM_UNIT_EXT.LEVELS = item.LEVELS;
                        aDM_UNIT_EXT.DESCRIPTIONS = item.DESCRIPTIONS;
                        aDM_UNIT_EXT.DELETED = item.DELETED;
                        aDM_UNIT_EXT.START_DATE = item.START_DATE;
                        aDM_UNIT_EXT.END_DATE = item.END_DATE;
                        aDM_UNIT_EXT.LAST_UPDATED = item.LAST_UPDATED;
                        admUnitExtList.Add(aDM_UNIT_EXT);
                        #endregion
                    }
                }
                jret.ADDRESS = addressList;
                jret.ADM_UNIT_EXT = admUnitExtList;


                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.RecordCount = retOfDownloadList.Count;
                jret.CurrentTime = System.Convert.ToInt64(DateTime.Now.ToString("yyyyMMddHHmmss", null)); //DHQGHN.Common.Utils.GetCurrentTimeNow();

                return jret;

                //return ret; // masterListBO.GetNewLists(_lastUpdated);
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw new FaultException<Fault.UnexpectedServiceFault>(
                    new Fault.UnexpectedServiceFault
                    {
                        ErrorMessage = ex.Message,
                        Source = ex.Source,
                        Target = ex.TargetSite.ToString(),
                        StackTrace = ex.StackTrace
                    },
                    new FaultReason(string.Format("{0}", "Service fault exception")));
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public HouseHoldAndResDataObject DownloadDuLieuBanDau(string EnumeratorID, string numberOfHouseHold, string pageIdx)
        {
            try
            {
                HouseHoldAndResDataObject jret = new HouseHoldAndResDataObject();
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.HOUSEHOLD = new List<HOUSEHOLD>();
                jret.RESIDENT = new List<RESIDENT>();

                int number, pageix;
                string id = "-1";

                if (string.IsNullOrEmpty(EnumeratorID) || string.IsNullOrEmpty(numberOfHouseHold) || string.IsNullOrEmpty(pageIdx))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                if (int.TryParse(numberOfHouseHold, out number) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số numberOfHouseHold sai định dạng!";
                    return jret;
                }
                id = EnumeratorID;
                if (int.TryParse(pageIdx, out pageix) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageIdx sai định dạng!";
                    return jret;
                }

                List<HOUSEHOLD> houseHoldArray = new List<HOUSEHOLD>();
                houseHoldArray = houseHoldBO.GetAllByENUMERATORIDTMP(id, number, pageix);
                List<RESIDENT> residentArray = residentBO.GetAllByENUMERATORIDTMP(id, number, pageix);
                jret.HOUSEHOLD = houseHoldArray;
                jret.RESIDENT = residentArray;
                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.NumberOfHouseHold = houseHoldArray.Count;

                return jret;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }


        public HouseHoldAndResDataObjectType2 DownloadDuLieuBanDauType2(string EnumeratorID, string numberOfHouseHold, string pageIdx)
        {
            try
            {
                HouseHoldAndResDataObjectType2 jret = new HouseHoldAndResDataObjectType2();
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();

                int number, pageix;
                string id = "-1";

                if (string.IsNullOrEmpty(EnumeratorID) || string.IsNullOrEmpty(numberOfHouseHold) || string.IsNullOrEmpty(pageIdx))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                if (int.TryParse(numberOfHouseHold, out number) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số numberOfHouseHold sai định dạng!";
                    return jret;
                }
                id = EnumeratorID;
                if (int.TryParse(pageIdx, out pageix) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageIdx sai định dạng!";
                    return jret;
                }

                List<HOUSEHOLD_DOWNLOAD> houseHoldArray = new List<HOUSEHOLD_DOWNLOAD>();
                houseHoldArray = houseHoldBO.GetAllByEnumerationIDType2(id, number, pageix);
                for (int i = 0; i < houseHoldArray.Count; i++)
                {
                    houseHoldArray[i].RESIDENTS = residentBO.GetByHouseHoldID(houseHoldArray[i].HOUSEHOLD_ID);
                }

                jret.HOUSEHOLD = houseHoldArray;
                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.NumberOfHouseHold = houseHoldArray.Count;
                return jret;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="lastUpdated"></param>
        /// <returns></returns>
        public HouseHoldAndResDataObject DownloadDuLieuDaDieuTra(string EnumeratorID, string numberOfHouseHold, string pageIdx)
        {
            try
            {
                HouseHoldAndResDataObject jret = new HouseHoldAndResDataObject();
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.HOUSEHOLD = new List<HOUSEHOLD>();
                jret.RESIDENT = new List<RESIDENT>();

                int number, pageix;
                string id = "-1";

                if (string.IsNullOrEmpty(EnumeratorID) || string.IsNullOrEmpty(numberOfHouseHold) || string.IsNullOrEmpty(pageIdx))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                if (int.TryParse(numberOfHouseHold, out number) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số numberOfHouseHold sai định dạng!";
                    return jret;
                }
                id = EnumeratorID;
                if (int.TryParse(pageIdx, out pageix) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageIdx sai định dạng!";
                    return jret;
                }

                List<HOUSEHOLD> houseHoldArray = new List<HOUSEHOLD>();
                houseHoldArray = houseHoldBO.GetAllByENUMERATORID(id, number, pageix);
                jret.NumberOfHouseHold = houseHoldArray.Count();
                List<RESIDENT> residentArray = residentBO.GetAllByENUMERATORID(id, number, pageix);
                jret.HOUSEHOLD = houseHoldArray;
                jret.RESIDENT = residentArray;
                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";

                return jret;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }

        public HouseHoldAndResDataObject DownloadDuLieuDaDieuTraTest(string EnumeratorID, string numberOfHouseHold, string pageIdx)
        {
            try
            {
                HouseHoldAndResDataObject jret = new HouseHoldAndResDataObject();
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();
                jret.HOUSEHOLD = new List<HOUSEHOLD>();
                jret.RESIDENT = new List<RESIDENT>();

                int number, pageix;
                string id = "-1";

                if (string.IsNullOrEmpty(EnumeratorID) || string.IsNullOrEmpty(numberOfHouseHold) || string.IsNullOrEmpty(pageIdx))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                if (int.TryParse(numberOfHouseHold, out number) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số numberOfHouseHold sai định dạng!";
                    return jret;
                }
                id = EnumeratorID;
                if (int.TryParse(pageIdx, out pageix) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageIdx sai định dạng!";
                    return jret;
                }

                List<HOUSEHOLD> houseHoldArray = new List<HOUSEHOLD>();
                houseHoldArray = houseHoldBO.GetAllByENUMERATORIDTest(id, number, pageix);
                jret.NumberOfHouseHold = houseHoldArray.Count();
                List<RESIDENT> residentArray = residentBO.GetAllByENUMERATORIDTest(id, number, pageix);
                jret.HOUSEHOLD = houseHoldArray;
                jret.RESIDENT = residentArray;
                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";

                return jret;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }

        #endregion


        public HouseHoldAndResDataObjectType2 DownloadDuLieuDaDieuTraType2(string EnumeratorID, string numberOfHouseHold, string pageIdx)
        {
            try
            {
                HouseHoldAndResDataObjectType2 jret = new HouseHoldAndResDataObjectType2();
                jret.CurrentTime = DHQGHN.Common.Utils.GetCurrentTimeNow();

                int number, pageix;
                string id = "-1";

                if (string.IsNullOrEmpty(EnumeratorID) || string.IsNullOrEmpty(numberOfHouseHold) || string.IsNullOrEmpty(pageIdx))
                {
                    jret.ErrorCode = -1;
                    jret.ErrorMessage = "Thiếu tham số";
                    return jret;
                }
                if (int.TryParse(numberOfHouseHold, out number) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số numberOfHouseHold sai định dạng!";
                    return jret;
                }
                id = EnumeratorID;
                if (int.TryParse(pageIdx, out pageix) == false)
                {
                    jret.ErrorCode = -3;
                    jret.ErrorMessage = "Tham số PageIdx sai định dạng!";
                    return jret;
                }

                List<HOUSEHOLD_DOWNLOAD> houseHoldArray = new List<HOUSEHOLD_DOWNLOAD>();
                houseHoldArray = houseHoldBO.GetAllByEnumerationIDType2(id, number, pageix);
                for (int i = 0; i < houseHoldArray.Count; i++)
                {
                    houseHoldArray[i].RESIDENTS = residentBO.GetByHouseHoldID(houseHoldArray[i].HOUSEHOLD_ID);
                }

                jret.HOUSEHOLD = houseHoldArray;
                jret.ErrorCode = 200;
                jret.ErrorMessage = "OK";
                jret.NumberOfHouseHold = houseHoldArray.Count;

                return jret;
            }
            catch (Exception ex)
            {
                logger.Error(ex.ToString());
                throw;
            }
        }
    }
}